package com.zim.ta_service.base.config;

import com.ejlchina.searcher.DbMapping;
import com.ejlchina.searcher.boot.BeanSearcherProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * author: alabimofa <br>
 * date: 2022/6/24 16:55 <br>
 */
@Configuration
@EnableConfigurationProperties(BeanSearcherProperties.class)
public class SearchBeanConfiguration {

	@Bean
	public DbMapping dbMapping(BeanSearcherProperties config) {
		SearchBeanDbMapping mapping = new SearchBeanDbMapping();
		BeanSearcherProperties.Sql.DefaultMapping conf = config.getSql().getDefaultMapping();
		mapping.setTablePrefix(conf.getTablePrefix());
		mapping.setUpperCase(conf.isUpperCase());
		mapping.setUnderlineCase(conf.isUnderlineCase());
		mapping.setRedundantSuffixes(conf.getRedundantSuffixes());
		mapping.setIgnoreFields(conf.getIgnoreFields());
		mapping.setDefaultInheritType(conf.getInheritType());
		mapping.setDefaultSortType(conf.getSortType());
		return mapping;
	}
}
